<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/icon.css"/>">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/yzr_style.css"/>">

<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
<title>药品出库</title>
</head>
<body>

<script type="text/javascript">
	$(function(){
		
		//获取当前登录用户的id
		var  outstockCkr_staffId = $("#tontyiStaffId").html();
		//选择提领单
		$("#yzr-outstock-draw").combogrid({onChange: function(newValue, oldValue){
			
			//根据id查找出仓存和药房
			var drawId = $("#yzr-outstock-draw").combogrid("getValue");
			$("#yzr-outstock-ckr").combogrid("setValue",outstockCkr_staffId);
			
			$.getJSON("queryDrawByIdYzr",{"medDrawId":drawId}, function(data){
				$("#yzr-outstock-store").combogrid("setValue",data.medDrawStoreId);
				$("#yzr-outstock-pharmacy").combogrid("setValue",data.medDrawPharmacyId);		
			});
			
			//根据id查找提领单详情
			$("#yzr-outstock-draw-dg").datagrid({
				url:'queryDrawDetByIdYzr',
				queryParams:{
					page:1, 
	    			rows:10,
	    			medDrawId: drawId
				}
			});
		}});
		
		//提交数据
		$("#yzr-outstock-submit").linkbutton({onClick: function(){
			var drawId = $("#yzr-outstock-draw").combogrid("getValue");
			var kind = $("#yzr_outstock_kind").combogrid("getValue");
			var ckr = $("#yzr-outstock-ckr").combogrid("getValue");
			var tlr = $("#yzr-outstock-tlr").combogrid("getValue");
			
			$("#yzr_outstock_form").form('submit',{
				url: 'addOutstockYzr',
				queryParams:{
					drawId: drawId,
					kind: kind,
					ckr: ckr,
					tlr: tlr
				},
			    onSubmit: function(){
			    	return $(this).form("validate");
			    },
			    success:function(data){			    	
					$.messager.alert('提示', "出库成功！");
					$(this).form("clear");
					//重新加载提领单
					$("#yzr-outstock-draw").combogrid({
						 url:'queryDrawByDrawStateYzr',
					});
					$('#yzr-outstock-draw-dg').datagrid('loadData', { total: 0, rows: [] }); 
					
					$('#tb-medDraw').datagrid("reload");
			    }
			});		
		}});
		
		
		//查看详情
		$("#yzr-outstock-detail-more").linkbutton({onClick: function(){
			var rows = $("#yzr-outstock-detail-dg").datagrid("getSelections");
			if(rows.length == 1){
				var outstockId = rows[0].medOutstockId;
				$('#yzr-outstockMed-detail-window').window("open");
				
				$.getJSON("queryOutstockByIdYzr", {"outstockId": outstockId}, function(data){
					//,,,medOutstockPerson,medOutstockStoreId,medOutstockTime,medOutstockWhere
					$("#yzr-outstockMed-detail-ckbh").linkbutton({text: data.medOutstockId});
					$("#yzr-outstockMed-detail-cklx").linkbutton({text: data.medOutstockKind});
					$("#yzr-outstockMed-detail-tldh").linkbutton({text: data.medOutstockMedDrawId});
					$("#yzr-outstockMed-detail-ckr").linkbutton({text: data.staffName});
					$("#yzr-outstockMed-detail-ck").linkbutton({text: data.storeName});
					$("#yzr-outstockMed-detail-yf").linkbutton({text: data.pharName});
					
				});	
				
				 //根据id查看详情	
				 $("#yzr-outstockMed-detail-dg").datagrid({
					url:'queryOutstockByOutIdYzr',
					width: '100%',
					queryParams:{
						outstockId: outstockId
					}
				});
			}else{
				$.messager.alert("提示", "请选择一条记录!");
			}
		}});
		
		//刷新
		$("#yzr-outstock-detail-reload").linkbutton({onClick: function(){
			$("#yzr-outstock-detail-dg").datagrid({
				url:'queryAllOutstockYzr',			
			});
		}});
		
		
		$('#yzr-outstock-tabs').tabs({
		    onSelect:function(title,index){
		        
		        if(title == '出库明细'){
		        	$("#yzr-display-outstock-none").show();
		        }else if(title == '查看出库详情'){
		        	$("#yzr-display-outstock-none").css("display","none");
		        }
		    }
		});
	});
</script>


	<!-- 提领单、出库类型、仓库、出库到药房、出库人、提领人 -->
	<!-- 出库数据 -->
	<div id="yzr-display-outstock-none">
	<form id="yzr_outstock_form" method="post" style="padding:10px;background:#ECF3FF;">
		<table style="width:100%;">
			<tr>
				<td style="width:35%;">
					<select class="easyui-combogrid" id="yzr-outstock-draw"
						data-options="
							label: '提领单号',
							labelAlign:'right',
							required:true,
							width: '85%',
							panelWidth: '305',
							panelHeight: 'auto',
							url: 'queryDrawByDrawStateYzr',
							pagination: true,
							pageSize: 8,
							pageList: [8, 16, 24, 32],
							idField: 'medDrawId',
							textField: 'medDrawId',
							columns: [[				
								{field:'medDrawId',title:'提领号',width:120},
								{field:'staffNameSp',title:'审批人',width:60},
								{field:'medDrawAutditState',title:'审批状态',width:60},
								{field:'medDrawDrawState',title:'提领状态',width:60}
							]]
					"></select>
				</td>
				<td style="width:33%;">
					<select id="yzr_outstock_kind" class="easyui-combobox" data-options="
					   		label: '出库类型',
							labelAlign:'right',
							required:true,
							width: '85%',
							panelWidth: '150',
							panelHeight: 'auto'">
					    
					    <option value="提领出库">提领出库</option>
					    <option value="调拨出库">调拨出库</option>
					</select>
				</td>
				
				<td style="width:33%;">
					<select class="easyui-combogrid" id="yzr-outstock-store"
						data-options="
							label: '被提领仓库',
							labelAlign:'right',
							required:true,
							width: '85%',
							panelWidth: '290',
							panelHeight: 'auto',
							url: 'queryAllStorehouse',
							pagination: true,
							pageSize: 8,
							pageList: [8, 16, 24, 32],
							idField: 'storeId',
							textField: 'storeName',
							columns: [[				
								{field:'storeName',title:'仓库名',width:100},
								{field:'storeKind',title:'类型',width:85},
								{field:'storeAddress',title:'地址',width:100}
							]]
					"></select>
				</td>
			</tr>
			<tr>
				<td>
					<select class="easyui-combogrid" id="yzr-outstock-pharmacy"
						data-options="
							label: '提领到药房',
							labelAlign:'right',
							required:true,
							width: '85%',
							panelWidth: '290',
							panelHeight: 'auto',
							url: 'queryAllPharmacy',
							pagination: true,
							pageSize: 8,
							pageList: [8, 16, 24, 32],
							idField: 'pharmacyId',
							textField: 'pharmacyName',
							columns: [[				
								{field:'pharmacyName',title:'药房名',width:100},
								{field:'staffName',title:'负责人',width:85},
								{field:'pharmacyAddress',title:'地址',width:100}
							]]
					"></select>
				</td>
				<td>
					<select class="easyui-combogrid" id="yzr-outstock-ckr"
						data-options="
							label: '出库人',
							width: '85%',
							labelAlign:'right',
							panelWidth: '290',
							panelHeight: 'auto',
							required:true,
							url: 'queryAllStaff',
							pagination: true,
							pageSize: 8,
							pageList: [8, 16, 24, 32],
							idField: 'staffNo',
							textField: 'staffName',
							columns: [[
								{field:'staffName',title:'姓名',width:100},
								{field:'departmentName',title:'部门',width:100},
								{field:'postName',title:'职务',width:85}
							]]
					"></select>
				</td>
				<td>
					<select class="easyui-combogrid" id="yzr-outstock-tlr"
						data-options="
							label: '提领人',
							width: '85%',
							labelAlign:'right',
							panelWidth: '290',
							panelHeight: 'auto',
							required:true,
							url: 'queryAllStaff',
							pagination: true,
							pageSize: 8,
							pageList: [8, 16, 24, 32],
							idField: 'staffNo',
							textField: 'staffName',
							columns: [[
								{field:'staffName',title:'姓名',width:100},
								{field:'departmentName',title:'部门',width:100},
								{field:'postName',title:'职务',width:85}
							]]
					"></select>
				</td>
			</tr>
		</table>
	</form>
	</div>					

	<!-- 订单明细 -->
	<div style="margin: 5px; margin-top:20px;">
	
		<div id="yzr-outstock-tabs" class="easyui-tabs" style="width:98%; margin-top:10px;" 
			data-options="plain:true,narrow:true">
			
			<!-- tab1 -->
			<div title="出库明细" style="padding:10px;">
				<table id="yzr-outstock-draw-dg" class="easyui-datagrid" 
							data-options="
							iconCls: 'icon-edit',
							singleSelect:true,
							toolbar: '#yzr-outstock-draw-toolbar',						
							width: '100%'
							">
						<thead>
							<tr><!-- 药品编号，药品名称，批号，规格，单位，数量
							medDrawDetMedId,medDrawDetMedName,medDrawDetBatchnumber,medDrawDetGuige,medDrawDetUnit,medDrawDetNumber -->
							
								<th data-options="field:'medDrawDetMedId',width:'23%',align:'center'">药品编号</th>			
								<th data-options="field:'medDrawDetMedName',width:'23%',align:'center'">药品名称</th>
								<th data-options="field:'medDrawDetBatchnumber',width:'20%',align:'center'">批号</th>
								<th data-options="field:'medDrawDetGuige',width:'13%',align:'center'">规格</th>
								<th data-options="field:'medDrawDetUnit',width:'8%',align:'center'">单位</th>
								<th data-options="field:'medDrawDetNumber',width:'13%',align:'center'">提领数量</th>
								
								<th data-options="field:'medDrawDetPrice',width:'13%',align:'center',hidden:true">单价</th>
							</tr>
						</thead>
				</table>
				<!-- 确认按钮 -->
				<div id="yzr-outstock-draw-toolbar">
					<a id="yzr-outstock-submit" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-ok'">出库</a>
				</div>
			</div>	
			
			<!-- tab2 -->
			<div  title="查看出库详情" style="padding:10px;">
				<table id="yzr-outstock-detail-dg" class="easyui-datagrid" 
					data-options="
						url: 'queryAllOutstockYzr',
						iconCls: 'icon-edit',	
						pagination: true,
						singleSelect: true,
						toolbar: '#yzr-outstock-detail-tb',
						pageSize: 16,
						pageList: [16, 32, 48, 54],						
						width: '100%',
						height: '400px'
						">
					<thead>
						<tr>
						<!-- 出库编号，药品提领单号,出库类型（调拨出库，提领出库），仓库编号，出库到，出库人，出库时间
								//medOutstockId,medOutstockKind,medOutstockMedDrawId,medOutstockPerson,
								medOutstockStoreId,medOutstockTime,medOutstockWhere-->	
							<th data-options="field:'XXX',width:'2%',checkbox:true">出库编号</th>
							<th data-options="field:'medOutstockId',width:'18%',align:'center'">出库编号</th>	
							<th data-options="field:'medOutstockMedDrawId',width:'18%',align:'center'">提领单号</th>				
							<th data-options="field:'medOutstockKind',width:'13%',align:'center'">出库类型</th>
							<th data-options="field:'storeName',width:'14%',align:'center'">从仓库</th>
							<th data-options="field:'pharName',width:'14%',align:'center'">到药房</th>
							<th data-options="field:'staffName',width:'10%',align:'center'">出库人</th>
							<th data-options="field:'medOutstockTime',width:'10%',align:'center'">出库时间</th>														
						</tr>
					</thead>
				</table>
				<div id="yzr-outstock-detail-tb">
					<a id="yzr-outstock-detail-more" class="easyui-linkbutton" data-options="iconCls:'icon-more',plain:true">查看详情</a>
					<a id="yzr-outstock-detail-reload" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true">刷新</a>					
				</div> 
			</div>	
			
									
		</div><!-- tab  -->						
	</div>
			
			
			
	<!--查看详情窗口 -->
	<div id="yzr-outstockMed-detail-window" class="easyui-window" title="查看出库详情" data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,iconCls:'icon-save',closed: true" style="width:70%;height:70%;">		
		<div class="easyui-layout" style="padding:0px;" data-options="fit:true">			
			<div data-options="region:'center'" style="padding:5px;border-top:none;border-left:none;border-right:none;">	
				
				<form id="yzr_outstockMed-detail_form" method="post" style="margin:10px;width:98%;">
					<table width="98%" style="margin:10px;">
						<tr>
							<td>出库编号:<a id="yzr-outstockMed-detail-ckbh" name="purchId" class="easyui-linkbutton" data-options="plain:true"></a></td>
							<td>出库类型:<a id="yzr-outstockMed-detail-cklx" name="purchTitle" class="easyui-linkbutton" data-options="plain:true"></a></td>
							<td>提领单号:<a id="yzr-outstockMed-detail-tldh" name="staffName" class="easyui-linkbutton" data-options="plain:true"></a></td>
							
						</tr>
						<tr>
							<td>出库人:<a id="yzr-outstockMed-detail-ckr" name="staffNameSp" class="easyui-linkbutton" data-options="plain:true"></a></td>
							<td>从仓库:<a id="yzr-outstockMed-detail-ck" name="purchAutditState" class="easyui-linkbutton" data-options="plain:true"></a></td>
							<td>到药房:<a id="yzr-outstockMed-detail-yf" name="purchAutditTime" class="easyui-linkbutton" data-options="plain:true"></a></td>
							
						</tr>
					</table>
						
					<div style="margin: 10px;">
						<div id="yzr-purchDet-tabs" class="easyui-tabs" style="width:98%; margin-top:10px;" 
							data-options="plain:true,narrow:true">
							
							<div title="入库药品明细" style="padding:10px;">
								<table id="yzr-outstockMed-detail-dg" class="easyui-datagrid"  style="margin-left:10px"
										data-options="
											iconCls: 'icon-edit',
											singleSelect: true,
											align: 'center',										
											width: '98%'
											">
										<thead>
										<tr>	<!-- 出库详情编号，出库编号，药品编号，药品名称，批号，规格，单位,单价，数量
												//medOutstockDetId,medChukuId,medOutstockDetBatchnumber,medOutstockDetGuige,
												medOutstockDetMedId,medOutstockDetMedName,medOutstockDetMoney,medOutstockDetNumber,medOutstockDetPrice,medOutstockDetUnit,, -->
												<th data-options="field:'medOutstockDetId',width:'20%',align:'center'">出库详情编号</th>		
												<th data-options="field:'medOutstockDetMedName',width:'20%',align:'center'">药品名称</th>
												<th data-options="field:'medOutstockDetBatchnumber',width:'15%',align:'center'">批号</th>
												<th data-options="field:'medOutstockDetGuige',width:'15%',align:'center'">规格</th>
												<th data-options="field:'medOutstockDetUnit',width:'15%',align:'center'">单位</th>
												<th data-options="field:'medOutstockDetNumber',width:'15%',align:'center'">出库数量</th>
											</tr>
										</thead>
								 </table>
							</div>						
						</div>				
					</div>
				</form>								
			</div>
					
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel', plain:true" href="javascript:$('#yzr-outstockMed-detail-window').window('close');" onclick="">取消</a>
			</div>			
		</div>
	</div>
	
	
</body>
</html>